package com.gimi.cloud.bbp.manage.controller.page;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.MyBeanUtils;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.page.PageColumnDTO;
import com.gimi.cloud.bbp.entity.page.PageColumn;
import com.gimi.cloud.bbp.manage.service.page.PageColumnService;

/**
 * 栏目
 * @author zhoufuhang
 *
 */
@RestController
public class PageColumnController {
	
	@Autowired private PageColumnService pageColumnService;
	
	/**
	 * 根据栏目ID获取
	 * @param dto
	 * @param response
	 */
	@RequestMapping("/pc/getPageColumnById")
	public Response getInfoById(@RequestBody PageColumnDTO dto, HttpServletResponse response) {
		return new Response(ResponseCodeEnum.SUCCESSED, pageColumnService.getInfoById(dto));
	}
	
	/**
	 * 根据模板ID添加栏目
	 * @param dto
	 * @param response
	 */
	@RequestMapping("/pc/addPageColumnByTemplateId")
	public Response addColumnByTemplate(@RequestBody PageColumnDTO dto, HttpServletResponse response) {
		pageColumnService.addColumnByTemplate(dto);
		return new Response(ResponseCodeEnum.SUCCESSED);
	}
	
	/**
	 * 根据ID删除栏目
	 * @param dto
	 * @param response
	 */
	@RequestMapping("/pc/delPageColumnAllById")
	public Response delAllById(@RequestBody PageColumnDTO dto, HttpServletResponse response) {
		pageColumnService.delAll(dto.getId());
		return new Response(ResponseCodeEnum.SUCCESSED);
	}
	
	/**
	 * 保存栏目
	 * @param dto
	 * @param response
	 */
	@RequestMapping("/pc/savePageColumn")
	public Response saveInfo(@RequestBody PageColumnDTO dto, HttpServletResponse response) {
		PageColumn entity = new PageColumn();
		MyBeanUtils.copyPropertiesIgnoreNullAndEmptyStr(dto, entity);
		pageColumnService.savePageConfig(entity);
		return new Response(ResponseCodeEnum.SUCCESSED);
	}

}
